package com.vision.utils;

import com.alibaba.fastjson2.JSON;
import com.vision.config.Constants;
import com.vision.pojo.vo.MessageVO;

import java.time.LocalDateTime;

public class MessageUtil {

    /**
     * 系统消息
     * @param content 消息内容
     * @return string 类型的消息
     */
    public static String notification(String content, String receiverUsername , Integer state) {
        MessageVO message = new MessageVO();
        message.setContent(content);
        message.setReceiverUsername(receiverUsername);
        message.setSenderUsername("系统消息");
        message.setIsSystem(1);
        message.setSendTime(LocalDateTime.now());
        message.setState(state);
        return JSON.toJSONString(message);
    }

    /**
     * 普通消息
     * @param content 消息内容
     * @param receiverUsername 接收者用户名
     * @param senderUsername 发送者用户名
     * @return string 类型的消息
     */
    public static String message(String content, String receiverUsername,String senderUsername) {
        MessageVO message = new MessageVO();
        message.setContent(content);
        message.setReceiverUsername(receiverUsername);
        message.setSenderUsername(senderUsername);
        message.setIsSystem(0);
        message.setSendTime(message.getSendTime());
        message.setState(Constants.WEBSOCKET_NORMAL_CODE);
        return JSON.toJSONString(message);
    }
}
